package com.wu.flandre.configuration;

import com.google.common.io.Resources;
import com.wu.flandre.util.CommonUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * SigarConfiguration <br/>
 *
 * @author xuan.wu <br/>
 * @date 2019/12/29 15:01 <br/>
 */
@Configuration
@Slf4j
public class SigarConfiguration {
    @Autowired
    CommonUtil commonUtil;

    @Bean
    public void loadSigarLib() {
        try {
            String libFile = Resources.getResource("lib/sigar-amd64-winnt.dll").getFile();
            String soFile = Resources.getResource("lib/libsigar-amd64-linux.so").getFile();
            if (commonUtil.isLinuxSystem()) {
                System.load(soFile);
            } else {
                System.load(libFile);
            }
            log.info("加载Sigar依赖成功");
        } catch (Exception e) {
            log.error("加载Sigar依赖失败:" + e.getMessage(), e);
        }
    }
}
